package main

import (
	"log"
)

func num() {
	db := sql()
	t := R{}
	book := t.Datas
	result := db.Find(&book)
	num := result.RowsAffected
	log.Println("一共", num, "条数据")
}

func Get() R {
	db := sql()
	t := R{}
	book := t.Datas
	result := db.Find(&book)
	num := result.RowsAffected
	log.Println("一共", num, "条数据")
	R := R{
		true,
		book,
	}
	return R
}
func Save(book Book) bool {
	db := sql()
	db.Save(&book)

	return true
}
func PutIn(json map[string]interface{}, book Book) bool {
	db := sql()
	db.Model(&book).Create(json)

	return true
}
func Dell(i string) R {
	db := sql()
	db.Unscoped().Delete(&Book{}, i)
	R := R{}
	intR(&R)

	return R
}
func GetByIdd(i string) R {
	db := sql()
	t := R{}
	book := t.Datas
	db.Where("id = ?", i).First(&book)
	R := R{
		true,
		book,
	}
	return R
}
func pages(NINT, MINT int) R {
	db := sql()
	t := R{}
	book := t.Datas
	log.Println(NINT, MINT)
	offset := (NINT - 1) * MINT
	db.Offset(offset).Limit(MINT).Find(&book)
	R := R{
		true,
		book,
	}
	return R
}
func page2(NINT int, MINT int, name string) *[]Book {

	db := sql()
	t := R{}
	book := t.Datas
	log.Println(NINT, MINT)
	offset := (NINT - 1) * MINT
	db.Offset(offset).Limit(MINT).Find(&book)
	R := R{
		true,
		book,
	}
	db.Find(&book).Where("name LIKE ?", "%"+name+"%").Offset(offset).Limit(MINT)
	return R.Datas
}
